import { _decorator, Component, Enum, find, Label, Node, Sprite, SpriteFrame } from 'cc';
import { WEAPONSHOW } from '../AshFramework/Datas/Constant';
import { BundleManager, Bundles } from '../AshFramework/Managers/BundleManager';
const { ccclass, property } = _decorator;

@ccclass('WeaponShow')
export class WeaponShow extends Component {

    @property({ type: Enum(WEAPONSHOW) })
    Type: WEAPONSHOW = WEAPONSHOW.NON;

    protected onLoad(): void {
        if (this.Type == WEAPONSHOW.NON) return;
        this.BulletNumLabel = this.node.getChildByName("子弹数量").getComponent(Label);
        if (this.Type == WEAPONSHOW.INSTANT) {
            this.BulletSprite = find("备用子弹/子弹Icon", this.node).getComponent(Sprite);
            this.BulletNameLabel = find("备用子弹/子弹名称", this.node).getComponent(Label);
        }
    }

    //#region 瞬发子弹
    BulletNumLabel: Label = null;

    //#region 填充子弹
    BulletSprite: Sprite = null;
    BulletNameLabel: Label = null;

    showBulletNum(num: number) {
        this.BulletNumLabel.string = num.toString();
    }

    showBullet(name: string = "") {
        if (name === "") {
            this.BulletSprite.spriteFrame = null;
            this.BulletNameLabel.string = "无备用";
            return;
        }
        BundleManager.LoadSpriteFrame(Bundles.BundleSprites, `子弹/${name}`).then((sf: SpriteFrame) => {
            this.BulletSprite.spriteFrame = sf;
            this.BulletNameLabel.string = name;
        })
    }

}


